package agent;

import processing.core.PVector;

public class AvoidEdgesBehavior extends Behavior {
	
	float repulsion = 0.5f;
	
	AvoidEdgesBehavior(Main p) {
		super(p);
	}
	
	public void apply(Agent a){
		super.apply(a);
		avoidEdges(a);
	}
	
	public void avoidEdges(Agent a) {
		PVector velocityAddition = new PVector(0,0);
		PVector position = a.getCurrentPosition();
		if (position.x < 100) velocityAddition.x = repulsion;
		if (position.x > p.width - 100) velocityAddition.x = -repulsion;
		if (position.y < 100) velocityAddition.y = repulsion;
		if (position.y > p.height - 100) velocityAddition.y = -repulsion;
		a.setVelocity(PVector.add(a.getCurrentVelocity(), velocityAddition));
	}

}
